﻿/**
 * Copyright (c) 2008 michiyasu wada
 * http://www.seyself.com/
 * 
 * Distributed under The MIT License.
 * [http://www.opensource.org/licenses/mit-license.php]
 */

package demo.buttons 
{
import com.seyself.utils.BitmapUtil;
import jp.progression.casts.CastButton;
import flash.text.TextField;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.display.DisplayObjectContainer;
import flash.display.Loader;
import flash.net.URLRequest;
import jp.progression.commands.DoTweener;
import jp.progression.scenes.SceneId;

public class ItemClipButton extends CastButton
{
    public var data:XML;
    
    public function get title():String
    {
        return itemData._title.text;
    }
    public function set title(value:String):void
    {
        itemData._title.text = value;
    }
    
    public function get description():String
    {
        return itemData._description.text;
    }
    public function set description(value:String):void
    {
        itemData._description.text = value;
    }
    
    //--------------------------------------------------------------------------
    //  Constructor
    //--------------------------------------------------------------------------
    public function ItemClipButton( data:XML=null ) 
    {
        if (data) setup( data );
    }
    
    //--------------------------------------------------------------------------
    //  Override Methods
    //--------------------------------------------------------------------------
    override protected function _onCastAdded():void
    {
        
    }
    
    override protected function _onCastRemoved():void
    {
        
    }
    
    
    //--------------------------------------------------------------------------
    //  Private Methods
    //--------------------------------------------------------------------------
    private function setup( data:XML )
    {
        this.data = data;
        var image = getChildByName("ProductImage");
        
        
        if( data.Thumbnail.URL.toString().length ){
            var request:URLRequest = new URLRequest( data.Thumbnail.URL );
            var loader:Loader = new Loader();
            loader.load( request );
            image.addChild( loader );
            
            loader.x = (75 - data.Thumbnail.Width ) / 2 >> 0;
            loader.y = (75 - data.Thumbnail.Height) / 2 >> 0;
            getChildByName("NoImageIcon").visible = false;
        }
        
        title = data.Title;
        description = data.Description;
        
        BitmapUtil.swapBitmap( itemData );
        
        // マウスオーバー時のツールチップ内容を指定します。
        toolTip.text = data.Title;
        
        //リンク先を指定
        //this.href = data.DetailPageURL;
        
        // クリック時に移動する先のシーン識別子を指定します。
        var detailId:String = "/demo/search/detail/" + data.ASIN;
        sceneId = new SceneId( detailId );
        
    }
    
}

}